package com.fqgj.sentry.controller.pc;


import com.fqgj.sentry.biz.pc.PolicySetBusiness;
import com.fqgj.sentry.biz.pc.vo.policyset.PolicySetResultVo;
import com.fqgj.sentry.biz.pc.vo.policyset.PolicySetVo;
import com.fqgj.sentry.common.annotations.ParamsValidate;
import com.fqgj.sentry.common.cache.RequestLocalInfo;
import com.fqgj.sentry.common.response.ApiOutput;
import com.fqgj.sentry.controller.pc.request.AddPolicySetVo;
import com.fqgj.sentry.controller.pc.request.UpdatePolicySetVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * Created with IntelliJ IDEA.
 * User: yujianfu (mr.vencnet@gmail.com)
 * Date: 2017/7/12
 * Time: 下午7:20
 */
@RequestMapping("/policySets")
@RestController
public class PolicySetsController {

    @Autowired
    private PolicySetBusiness policySetBusiness;

    @ParamsValidate
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public ApiOutput add(@RequestBody AddPolicySetVo addPolicySetVo) {
        policySetBusiness.addPolicySet(addPolicySetVo);
        return new ApiOutput<>();
    }

    @ParamsValidate
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public ApiOutput update(@RequestBody UpdatePolicySetVo updatePolicySetVo) {
        policySetBusiness.updatePolicySet(updatePolicySetVo);
        return new ApiOutput<>();
    }

    @ParamsValidate
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public ApiOutput list() {
        List<PolicySetVo> policySetVoList = policySetBusiness.queryPolicySetForPage(RequestLocalInfo.getCurrentAppCode(), RequestLocalInfo.getCurrentMerchantId());
        return new ApiOutput<>(policySetVoList);
    }

    @RequestMapping(value = "/{policySetsId}/delete", method = RequestMethod.POST)
    public ApiOutput delete(@PathVariable(value = "policySetsId") Long policySetsId) {
        policySetBusiness.deletePolicySet(policySetsId);
        return new ApiOutput<>();
    }

    /**
     * 策略集结果 列表
     *
     * @param policySetsId
     * @return
     */
    @RequestMapping(value = "/{policySetsId}/result/list", method = RequestMethod.POST)
    public ApiOutput queryResultList(@PathVariable(value = "policySetsId") Long policySetsId) {
        PolicySetResultVo policySetResult = policySetBusiness.queryPolicySetResult(policySetsId);
        return new ApiOutput<>("policySetResult", policySetResult);
    }


    /**
     * 策略集  执行结果修改
     *
     * @param policySetResultVo
     * @return
     */
    @RequestMapping(value = "/result/update", method = RequestMethod.POST)
    public ApiOutput policySetResultUpdate(@RequestBody PolicySetResultVo policySetResultVo) {
        policySetBusiness.policySetResultUpdate(policySetResultVo);
        return new ApiOutput<>();
    }
}
